package Task;
import java.util.Scanner;
public class task1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();//读取测试组数
        for (int t = 0; t < T; t++) {
            int n = scanner.nextInt();//读取比赛场数
            int k = scanner.nextInt();//读取连胜奖励星数
            String results = scanner.next();//读取比赛结果字符串
            System.out.println(Differenec(n,k,results));
        }
        scanner.close();
    }

    private static int Differenec(int n, int k, String results) {
        int stars = 0;//初始星数
        int count = 0;//连胜次数
        for (int i = 0; i < n; i++) {
            if (results.charAt(i) == 'W') {
                count++;
                stars++;//每一赢一次就加一颗星
                if (count == k) {
                    //当连胜达到k时获得额外星数
                    stars--;
                    stars+=k;
                    count = 0;//重置连胜次数

                }


            }else{
                stars--;
                count = 0;//输了就重置连胜次数

            }

        }
        return stars;//返回最终的星数和初始星数的差
    }
}
